package com.icss.train_sys_back.controller.admin.statistics_manage;

import com.icss.train_sys_back.entity.ResponseResult;
import com.icss.train_sys_back.entity.statistics_manage.PassengerFlowEntity;
import com.icss.train_sys_back.entity.statistics_manage.PassengerTrendEntity;
import com.icss.train_sys_back.entity.statistics_manage.PassengerTimeDistributionEntity;
import com.icss.train_sys_back.service.statistics_manage.PassengerStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author 小泽
 * @createTime 2025/10/10 9:23
 */
@RestController
@RequestMapping("/admin/statistics/passenger")
@Slf4j
public class PassengerStatisticsController {
    @Autowired
    private PassengerStatisticsService passengerStatisticsService;

    //客流分析核心数据展示
    @GetMapping("/summary")
    public ResponseResult passengerFlowSummary(@RequestParam(required = false) String dateType,
                                               @RequestParam(required = false) Integer station,
                                               @RequestParam(required = false) String startDate,
                                               @RequestParam(required = false) String endDate) {
        log.info("客流分析核心数据展示 dateType = {} ,  startDate = {} , endDate = {} , stationId = {} ",
                dateType, startDate, endDate, station);
        PassengerFlowEntity passengerFlow = passengerStatisticsService.PassengerFlowSummary(dateType, station, startDate, endDate);
        return ResponseResult.success(passengerFlow);
    }

    //客流量趋势分析 - 修改为接收时间跨度参数
    @GetMapping("/trend")
    public ResponseResult passengerTrend(@RequestParam(required = false, defaultValue = "week") String dateType,
                                        @RequestParam(required = false) Integer station,
                                        @RequestParam(required = false) String startDate,
                                        @RequestParam(required = false) String endDate) {
        log.info("客流量趋势分析 dateType = {} ,  startDate = {} , endDate = {} , stationId = {} ",
                dateType, startDate, endDate, station);
        
        // 根据传入的dateType类型，查询对应时间范围的数据
        PassengerTrendEntity passengerTrend = passengerStatisticsService.passengerTrend(dateType, station, startDate, endDate);
        return ResponseResult.success(passengerTrend);
    }

    //热门车站客流分布数据
    @GetMapping("/stationDistribution")
    public ResponseResult getStationDistribution(@RequestParam(required = false) String dateType,
                                                 @RequestParam(required = false) Integer station,
                                                 @RequestParam(required = false) String startDate,
                                                 @RequestParam(required = false) String endDate) {
        log.info("热门车站客流分布数据 dateType = {} ,  startDate = {} , endDate = {} , stationId = {} ",
                dateType, startDate, endDate, station);
        List<Map<String, Object>> stationDistribution = passengerStatisticsService.getStationDistribution(dateType, station, startDate, endDate);
        return ResponseResult.success(stationDistribution);
    }

    //客流量时段分布数据
    @GetMapping("/timeDistribution")
    public ResponseResult getTimeDistribution(@RequestParam(required = false) String dateType,
                                             @RequestParam(required = false) Integer station,
                                             @RequestParam(required = false) String startDate,
                                             @RequestParam(required = false) String endDate) {
        log.info("客流量时段分布数据 dateType = {} ,  startDate = {} , endDate = {} , stationId = {} ",
                dateType, startDate, endDate, station);
        PassengerTimeDistributionEntity timeDistribution = passengerStatisticsService.getPassengerTimeDistribution(dateType, station, startDate, endDate);
        return ResponseResult.success(timeDistribution);
    }

























}




